<template>
    <div>
        <div v-if="props.item.transport_type == 1">
            <div v-if="itemList.length != 0">
                <div class="zuidaBox" >
                    <div class="flex align_center" style="height:50px">
                        <div style="font-size:20px;font-weight:600;margin-right:20px">费用合计</div>
                    </div>
                    <div class="tab_border" style="width: 100%;">
                        <div class="flex" style="background: rgba(242, 243, 245, 1);">
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>计费类型</div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>计费名称</div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>原金额</div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>实际付款金额</div>
                            </div>
                        </div>
                        <div class="flex" style="width: 100%;box-sizing: border-box;" v-for="(item,index) in zongList" :key="index">
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>{{item.price_type == ''?'':handlePriceType(item.price_type)}}</div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>{{item.pay_name}}</div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>{{item.pay_price == ''?'':(item.pay_price - 0).toFixed(2)}}</div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>{{item.pay_real_price == ''?'':(item.pay_real_price - 0).toFixed(2)}}</div>
                            </div>
                        </div>
                        <div class="flex" style="width: 100%;box-sizing: border-box;" >
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>合计</div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div></div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>{{zongPay_prices}}</div>
                            </div>
                            <div class="flex flex_1 bor_r bor_b pad412 align_center justify_center" style="min-height: 37px;">
                                <div>{{zongpay_real_prices}}</div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="flex align_center" style="height:50px">
                        <div style="font-size:20px;font-weight:600;margin-right:20px">费用明细</div>
                        <div style="color:#165dff;cursor: pointer;" @click="zhankaiShow = !zhankaiShow">{{zhankaiShow?'收起':'展开'}}</div>
                    </div>
                    <div v-if="zhankaiShow">
                        <div v-for="(item, index) in itemList" :key="index" class="box">
                            <div class="flex align_center" style="margin-bottom: 1.5%;padding-left: 24px;">
                                <!-- <div class="flex align_center justify_center" style="margin-right: 10px;"
                                    :class="item.is_confirm == 0 ? 'chek' : 'act_chek'"
                                    @click="item.is_confirm == 0 ? item.is_confirm = 1 : item.is_confirm = 0">
                                    <icon-check style="color:#fff" v-if="item.is_confirm == 1" />
                                </div> -->
                                <div style="font-weight: 600;margin-right: 40px;">账单号：{{ item.order_number }}</div>
                                <div style="margin-right: 40px;">创建时间：{{ item.created_at }}</div>
                                <div class="flex align_center" style="margin-right: 40px;">
                                    <div>付款人：</div>
                                    <a-select v-model="item.pay_dept_id" style="width:390px;"
                                        @change="handleSelectPay_dept_id($event, index)" :options="dept_list"
                                        :field-names="{ value: 'id', label: 'name' }" :filter-option="filterOption"
                                        :disabled="true"
                                        allow-clear allow-search placeholder="请选择公司" />
                                </div>
                            </div>
                            <a-table
                                 :columns="tablecolumnsts"
                                :data="item.detail" :pagination='false' :span-method="spanMethodAll"
                                :bordered="{ wrapper: true, cell: true }">
                                <template #price_type="{ record, rowIndex }">
                                    <div class="flex align_center cursor" v-if="record.type == 0">
                                        <!-- <div class="flex align_center justify_center" style="margin-right: 10px;"
                                            :class="record.is_confirm == 0 ? 'chek' : 'act_chek'">
                                            <icon-check style="color:#fff" v-if="record.is_confirm == 1" />
                                        </div> -->
                                        <div>{{ handletuhuanPriceType(record.price_type) }}</div>
                                    </div>
                                    <div v-if="record.type == 1">
                                        <a-select v-model="record.price_type" style="width:120px;"
                                            :options="price_typeList" :field-names="{ value: 'key', label: 'title' }"
                                            :filter-option="filterOption" allow-clear allow-search placeholder="计费类型"
                                            @change="handleSelect($event, index, rowIndex)" />
                                    </div>
                                    <div v-if="record.type == 2">
                                        <a-link @click="handleAdd(index, rowIndex, 1)"><icon-plus /> 添加费用项</a-link>
                                    </div>
                                </template>
                                <template #no_tax_price="{ record }">
                                    <div v-if="record.price_type && record.pay_real_price">{{ (record.no_tax_price -
                                        0).toFixed(2) }}</div>
                                    <div v-else></div>
                                </template>
                                <template #tax_price="{ record }">
                                    <div v-if="record.price_type && record.pay_real_price">{{ (record.tax_price -
                                        0).toFixed(2) }}</div>
                                    <div v-else></div>
                                </template>
                                <template #pay_name="{ record }">
                                    <div v-if="record.type == 0">{{ record.pay_name }}</div>
                                    <div v-if="record.type == 1" @click.stop>
                                        <a-input v-model="record.pay_name" placeholder="项目名称" allow-clear />
                                    </div>
                                </template>
                                <template #pay_price="{ record, rowIndex }">
                                    <div v-if="record.type == 0">{{ (record.pay_price - 0).toFixed(2) }}</div>
                                </template>
                                <template #pay_real_price="{ record, rowIndex }">
                                    <div v-if="record.type == 0">{{ (record.pay_real_price - 0).toFixed(2) }}</div>
                                    <div v-if="record.type == 2">{{ (item.zongpay_real_price - 0).toFixed(2) }}</div>
                                </template>
                                <template #modify_price="{ record, rowIndex }">
                                    <div v-if="record.type == 0" @click.stop>
                                        <a-input v-model="record.modify_price" placeholder="修改金额" allow-clear
                                            @input="handleInput($event, index, rowIndex)" />
                                    </div>
                                    <div v-if="record.type == 1" @click.stop>
                                        <a-input v-model="record.modify_price" placeholder="修改金额" allow-clear
                                            @input="handleInput($event, index, rowIndex)" />
                                    </div>
                                    <div v-if="record.type == 2">{{(item.zongmodify_price - 0).toFixed(2)}}元</div>
                                </template>
                                <template #remark="{ record }">
                                    <div v-if="record.type != 2">
                                        <a-input v-model="record.remark" placeholder="备注" allow-clear />
                                    </div>
                                    <div  v-if = "record.type == 2">
                                        <div>{{(item.zongpay_real_price - 0)>(item.zongmodify_price - 0)?'累计减少:' :'累计增加:'}} <text style="color:red">{{(item.zongpay_real_price - 0)>(item.zongmodify_price - 0)?((item.zongpay_real_price - 0)-(item.zongmodify_price - 0)) + '元':((item.zongmodify_price - 0)-(item.zongpay_real_price - 0)) + '元'}}</text> </div>
                                    </div>
                                </template>
                                <template #caozuo="{ record, rowIndex }">
                                    <div v-if="record.type == 0">-</div>
                                    <div v-if="record.type == 1">
                                        <a-link @click="handleAdd(index, rowIndex, 2)">删除</a-link>
                                    </div>
                                </template>

                            </a-table>
                        </div>
                    </div>
                </div>
            
                <div class="flex justify_between align_center" style="margin-top: 12px;">
                    <div class="flex">
                        
                    </div>
                    <div class="flex">
                        <!-- handleCel -->
                        <a-button style="margin-right: 20px;"  @click="handleCel">取消支付</a-button>
                        <!-- zhifuShow = true -->
                        <a-popconfirm @ok="handleZhifu" content="是否修改账单?">
                            <a-button type="primary">确认修改</a-button>
                        </a-popconfirm>
                    </div>
                </div>
            </div>
            
            <div v-if="itemList.length == 0">
                <a-empty />
            </div>
        </div>
        <div v-else>
            <div class="zuidaBox" v-if="itemList.length != 0">
                <div v-for="(item, index) in itemList" :key="index" class="box">
                    <div class="flex align_center" style="margin-bottom: 1.5%;padding-left: 24px;">
                        <!-- <div class="flex align_center justify_center" style="margin-right: 10px;"
                            :class="item.is_confirm == 0 ? 'chek' : 'act_chek'"
                            @click="item.is_confirm == 0 ? item.is_confirm = 1 : item.is_confirm = 0">
                            <icon-check style="color:#fff" v-if="item.is_confirm == 1" />
                        </div> -->
                        <div style="font-weight: 600;margin-right: 40px;">账单号：{{ item.order_number }}</div>
                        <div style="margin-right: 40px;">创建时间：{{ item.created_at }}</div>
                        <div class="flex align_center" style="margin-right: 40px;">
                            <div>付款人：</div>
                            <a-select v-model="item.pay_dept_id" style="width:390px;"
                                @change="handleSelectPay_dept_id($event, index)" :options="dept_list"
                                :field-names="{ value: 'id', label: 'name' }" :filter-option="filterOption" :disabled="true"
                                allow-clear allow-search placeholder="请选择公司" />
                        </div>
                    </div>
                    <a-table  :columns="tablecolumnsts"
                        :data="item.detail" :pagination='false' :span-method="spanMethodAll"
                        :bordered="{ wrapper: true, cell: true }">
                        <template #price_type="{ record, rowIndex }">
                            <div class="flex align_center cursor" v-if="record.type == 0">
                                <!-- <div class="flex align_center justify_center" style="margin-right: 10px;"
                                    :class="record.is_confirm == 0 ? 'chek' : 'act_chek'">
                                    <icon-check style="color:#fff" v-if="record.is_confirm == 1" />
                                </div> -->
                                <div>{{ handletuhuanPriceType(record.price_type) }}</div>
                            </div>
                            <div v-if="record.type == 1">
                                <a-select v-model="record.price_type" style="width:120px;"
                                    :options="price_typeList" :field-names="{ value: 'key', label: 'title' }"
                                    :filter-option="filterOption" allow-clear allow-search placeholder="计费类型"
                                    @change="handleSelect($event, index, rowIndex)" />
                            </div>
                            <div v-if="record.type == 2">
                                <a-link @click="handleAdd(index, rowIndex, 1)"><icon-plus /> 添加费用项</a-link>
                            </div>
                        </template>
                        <template #no_tax_price="{ record }">
                            <div v-if="record.price_type && record.pay_real_price">{{ (record.no_tax_price -
                                0).toFixed(2) }}</div>
                            <div v-else></div>
                        </template>
                        <template #tax_price="{ record }">
                            <div v-if="record.price_type && record.pay_real_price">{{ (record.tax_price -
                                0).toFixed(2) }}</div>
                            <div v-else></div>
                        </template>
                        <template #pay_name="{ record }">
                            <div v-if="record.type == 0">{{ record.pay_name }}</div>
                            <div v-if="record.type == 1" @click.stop>
                                <a-input v-model="record.pay_name" placeholder="项目名称" allow-clear />
                            </div>
                        </template>
                        <template #pay_price="{ record, rowIndex }">
                            <div v-if="record.type == 0">{{ (record.pay_price - 0).toFixed(2) }}</div>
                        </template>
                        <template #pay_real_price="{ record, rowIndex }">
                            <div v-if="record.type == 0">{{ (record.pay_real_price - 0).toFixed(2) }}</div>
                            <div v-if="record.type == 2">{{ (item.zongpay_real_price - 0).toFixed(2) }}</div>
                        </template>
                        <template #modify_price="{ record, rowIndex }">
                            <div v-if="record.type == 0" @click.stop>
                                <a-input v-model="record.modify_price" placeholder="修改金额" allow-clear
                                    @input="handleInput($event, index, rowIndex)" />
                            </div>
                            <div v-if="record.type == 1" @click.stop>
                                <a-input v-model="record.modify_price" placeholder="修改金额" allow-clear
                                    @input="handleInput($event, index, rowIndex)" />
                            </div>
                            <div v-if="record.type == 2">{{(item.zongmodify_price - 0).toFixed(2)}}元</div>
                        </template>
                        <template #remark="{ record }">
                            <div v-if="record.type != 2">
                                <a-input v-model="record.remark" placeholder="备注" allow-clear />
                            </div>
                            <div v-if = "record.type == 2">
                                {{(item.zongpay_real_price - 0)>(item.zongmodify_price - 0)?'减少' +((item.zongpay_real_price - 0)-(item.zongmodify_price - 0)) + '元':'增加' +((item.zongmodify_price - 0)-(item.zongpay_real_price - 0)) + '元' }}
                            </div>
                        </template>
                        <template #caozuo="{ record, rowIndex }">
                            <div v-if="record.type == 0">-</div>
                            <div v-if="record.type == 1">
                                <a-link @click="handleAdd(index, rowIndex, 2)">删除</a-link>
                            </div>
                        </template>

                    </a-table>
                </div>
            </div>
            <div class=" flex align_center" style="padding: 10px 0 0;border-top: 1px solid rgba(0, 0, 0, .15);"
                v-if="itemList.length != 0">
                <div class="flex flex_1 justify_around">
                    <!-- <div>不含税合计金额：{{handleZongPrice(3)}}</div> -->
                    <!-- <div>税额合计金额：{{handleZongPrice(4)}}</div> -->
                    <!-- <div>原合计金额：{{ handleZongPrice(1) }}</div>
                    <div>实际支付合计金额：{{ handleZongPrice(2) }}</div> -->
                </div>
                <div class="flex">
                    <a-button style="margin-right: 20px;" @click="handleCel">取消支付</a-button>
                    <!-- zhifuShow = true -->
                    <a-popconfirm @ok="handleZhifu" content="是否修改账单?">
                        <a-button type="primary">确认修改</a-button>
                    </a-popconfirm>

                </div>
            </div>
            <div v-if="itemList.length == 0">
                <a-empty />
            </div>
        </div>

        <a-modal :mask-closable="false" v-model:visible="zhifuShow" title="支付" @cancel="zhifuShow = false" :width="600"
            :on-before-ok="handelzhifuOk">
            <div class="" style="margin-bottom: 2%;padding-left: 24px;height: 300px;">
                <div class="flex align_center" style="margin-bottom: 2%;">
                    <div style="width: 80px;">结算方式：</div>
                    <a-radio-group v-model="jiesuan" :options="jiesuanOptions" />
                </div>
                <div v-if="jiesuan == '1'" style="margin-bottom: 2%;">
                    <div style="margin-bottom: 2%;">实际付款金额：{{ tab == 1 ? handleZongPrice(2) : handleZongPricecb(2) }}元</div>
                    <div>当前可用余额：{{ availableAmount }}元</div>
                </div>
                <div v-if='jiesuan == "3"'>
                    <div style="display: flex;align-items: center;margin-bottom: 2%;">
                        <div style="width: 80px;">支付方式</div>
                        <a-radio-group v-model="zhifu" :options="zhifuOptions" />
                    </div>
                    <!-- <div style="display: flex;align-items: center;margin-bottom: 2%;">
                            <div style="width: 80px;">开户行</div>
                            <div >{{opening_bank}}</div>
                        </div>
                        <div style="display: flex;align-items: center;margin-bottom: 2%;">
                            <div style="width: 80px;">收款账户</div>
                            <div >{{account}}</div>
                        </div>
                        <div style="display: flex;align-items: center;margin-bottom: 2%;">
                            <div style="width: 80px;">开户名称</div>
                            <div >{{account_name}}</div>
                        </div>
                        <div style="display: flex;margin-bottom: 2%;">
                            <div style="width: 80px;">上传凭证</div>
                            <ma-upload v-model="fileList" returnType='url' />
                        </div> -->
                </div>
                <div style="display: flex;align-items: center;margin-bottom: 2%;">
                    <div style="width: 80px;">支付时间</div>
                    <a-date-picker style="width: 100%; " show-time v-model="pay_date" format="YYYY-MM-DD HH:mm" />
                </div>

            </div>
        </a-modal>

        <!-- 打印派送单 -->
        <a-modal :mask-closable="false" 
            v-model:visible="shoujuShow"
            width="auto"
            title="打印收据"
            ok-text="打印"
            @cancel="quxiaoshouju"
            :footer="false"
        >
            <shouju :user="user" :row="shoujuItem"  v-if="shoujuShow"></shouju>
        </a-modal>
    </div>
</template>

<script setup>
import { defineProps, defineEmits, ref, reactive, onMounted,watch } from "vue";
import { useAppStore, useUserStore, useMessageStore } from "@/store";
import FinancialPayOrder from "@/api/financial/financialPayOrder";
import { request } from "@/utils/request.js";
import commonApi from "@/api/common";
import tool from '@/utils/tool'
import { Message } from "@arco-design/web-vue";
const emit = defineEmits(['quxiao', 'shuaxin'])
import { pinyin } from "pinyin-pro"
import shouju from "@/components/shoukuan/index.vue"
const userStore = useUserStore()
const user = userStore.user
const shoujuShow = ref(false)
const shoujuItem = ref({})
const props = defineProps({
    item: Object,
})
const availableAmount = ref(0)
const tab = ref(1)
const zongPrice = ref(0)
const itemData = ref({
    page: 1,
    pageSize: 100,
})
const cbitemData = ref({
    page: 1,
    pageSize: 100,
})
const zhifuData = ref({
    prediction_id: '',
    pay_items_json: [],
})
const zhifu = ref('3')
const jiesuan = ref('')
const opening_bank = ref()
const pay_date = ref(tool.dateFormat(
    Math.round(new Date().getTime() / 1000).toString(),
    "yyyy-MM-dd hh:mm:ss"
))
const account = ref()
const account_name = ref()
const fileList = ref('')
const zhifuOptions = ref([
    { label: '对公转账', value: '3' },
    { label: '现金', value: '2' },
    { label: '惠支付', value: '1' },
])
const dept_list = ref([])
const paydept_list = ref([])
const itemList = ref([])
const cbitemList = ref([])
const price_typeList = ref([])    // 计费类型
const zhifuShow = ref(false)
const shuilvList = ref([])
const zhankaiShow = ref(true)
const jiesuanOptions = ref([
    {
        label: "现结",
        value: "3",
        disabled: true,
    },
    {
        label: "周期结算",
        value: "2",
        disabled: true,
    },
    {
        label: "预付款",
        value: "1",
        disabled: true,
    }
])

// 显示总计
const zongList = ref([])
const zongListCB = ref([])
const zongPay_prices = ref('0')
const zongpay_real_prices = ref('0')
const zongPay_pricesCB = ref('0')
const zongpay_real_pricesCB = ref('0')
// 账单修改数据
const handleShujuFormat = ()=>{
    let detailArr = []
    itemList.value.map((v, i) => {
        let zongpay_real_price = 0
        let zongmodify_price = 0
        v.detail.map((vv, ii) => {
            // console.log('vv',vv)
            if ((vv.type == 0) && vv.is_confirm == 1) {
                detailArr.push(vv)
                zongmodify_price += (vv.modify_price - 0)
                zongpay_real_price += (vv.pay_real_price - 0)
            }
            if (vv.type == 1) {
                if (vv.pay_name != '' && vv.modify_price != '') {
                    console.log('这是什么玩意',vv.modify_price)
                    detailArr.push(vv)
                    zongmodify_price += (vv.modify_price - 0)
                    zongpay_real_price += (vv.pay_real_price - 0)
                }
            }
        })
        
        v.zongmodify_price = zongmodify_price.toFixed(2)
        v.zongpay_real_price = zongpay_real_price.toFixed(2)
    })
    let arr = []
    let detailArrs = JSON.parse(JSON.stringify(detailArr))
    detailArrs.map((v, i) => {
        if(arr.length == 0){
            arr.push(v)
        }else{
            let num = arr.findIndex(item=>{
                return item.pay_name == v.pay_name
            })
            if(num == -1){
                arr.push(v)
            }else{
                arr[num].pay_price = (arr[num].pay_price - 0) + (v.pay_price - 0)
                arr[num].pay_real_price = (arr[num].pay_real_price - 0) + (v.pay_real_price - 0)
            }
        }
    })
    let pay_prices = 0
    let pay_real_prices = 0
    arr.map((v, i) => {
        pay_prices += (v.pay_price - 0)
        pay_real_prices += (v.pay_real_price - 0)
    })
    
    zongList.value = arr
    zongPay_prices.value = pay_prices.toFixed(2)
    zongpay_real_prices.value = pay_real_prices.toFixed(2)
}
const quxiaoshouju = ()=>{
    emit("shuaxin")
}
// 成本账单修改数据
const handleShujuFormatCB = ()=>{
    let detailArr = []
    cbitemList.value.map((v, i) => {
        let zongPay_price = 0
        let zongpay_real_price = 0
        v.detail.map((vv, ii) => {
            // console.log('vv',vv)
            if ((vv.type == 0) && vv.is_confirm == 1) {
                detailArr.push(vv)
                zongPay_price += (vv.pay_price - 0)
                zongpay_real_price += (vv.pay_real_price - 0)
            }
            if (vv.type == 1) {
                if (vv.price_type != '' && vv.pay_name != '' && vv.pay_price != '' && vv.pay_real_price != '') {
                    detailArr.push(vv)
                    zongPay_price += (vv.pay_price - 0)
                    zongpay_real_price += (vv.pay_real_price - 0)
                }
            }
        })
        v.zongPay_price = zongPay_price
        v.zongpay_real_price = zongpay_real_price
    })
    console.log('itemList:',itemList.value)
    let arr = []
    let detailArrs = JSON.parse(JSON.stringify(detailArr))
    detailArrs.map((v, i) => {
        if(arr.length == 0){
            arr.push(v)
        }else{
            let num = arr.findIndex(item=>{
                return item.pay_name == v.pay_name
            })
            if(num == -1){
                arr.push(v)
            }else{
                arr[num].pay_price = (arr[num].pay_price - 0) + (v.pay_price - 0)
                arr[num].pay_real_price = (arr[num].pay_real_price - 0) + (v.pay_real_price - 0)
            }
        }
    })
    console.log("arr:",arr)
    let pay_prices = 0
    let pay_real_prices = 0
    arr.map((v, i) => {
        pay_prices += (v.pay_price - 0)
        pay_real_prices += (v.pay_real_price - 0)
    })
    zongListCB.value = arr
    zongPay_pricesCB.value = pay_prices.toFixed(2)
    zongpay_real_pricesCB.value = pay_real_prices.toFixed(2)
}

const handlePriceType = (type) =>{
    let name = ''
    price_typeList.value.map((v, i) => {
        if (v.key == type) {
            name = v.title
        }
    })
    return name
}
watch(itemList, (newValue, oldValue) => {
  console.log(`newValue:`,newValue)
  handleShujuFormat()
},{ deep: true })





const tablecolumnstscb = [
    {
        title: '车号',
        dataIndex: 'car_nos',
        width: 120,

    },
    {
        title: '计费类型',
        dataIndex: 'price_type',
        width: 140,
        slotName: 'price_type'
    },
    {
        title: '收费公司',
        dataIndex: 'pay_dept_id',
        width: 160,
        slotName: 'pay_dept_id'
    },
    {
        title: '收费项目',
        dataIndex: 'pay_name',
        width: 140,
        slotName: 'pay_name'
    },
    // {
    //     title: '不含税金额',
    //     dataIndex: 'no_tax_price',
    //     width: 80,
    //     slotName: 'no_tax_price'
    // },
    // {
    //     title: '税额',
    //     dataIndex: 'tax_price',
    //     width: 80,
    //     slotName: 'tax_price'
    // },
    {
        title: '原金额',
        dataIndex: 'pay_price',
        width: 120,
        slotName: 'pay_price'
    },
    {
        title: '实际金额',
        dataIndex: 'pay_real_price',
        width: 120,
        slotName: 'pay_real_price'
    },
    {
        title: '备注',
        dataIndex: 'remark',
        width: 140,
        slotName: 'remark'
    },
    {
        title: '操作',
        dataIndex: 'caozuo',
        slotName: 'caozuo',
        width: 80,
    },
];
const tablecolumnsts = [
    {
        title: '车号',
        dataIndex: 'car_nos',
        width: 120,

    },
    {
        title: '计费类型',
        dataIndex: 'price_type',
        width: 140,
        slotName: 'price_type'
    },
    {
        title: '收费项目',
        dataIndex: 'pay_name',
        width: 140,
        slotName: 'pay_name'
    },
    //    {
    //        title: '不含税金额',
    //        dataIndex: 'no_tax_price',
    //        width:80,
    //        slotName:'no_tax_price'
    //    },
    //    {
    //        title: '税额',
    //        dataIndex: 'tax_price',
    //        width:80,
    //        slotName:'tax_price'
    //    },

    {
        title: '原金额',
        dataIndex: 'pay_price',
        width: 120,
        slotName: 'pay_price'
    },
    {
        title: '实际金额',
        dataIndex: 'pay_real_price',
        width: 120,
        slotName: 'pay_real_price'
    },
    {
        
        title: '修改后金额',
        dataIndex: 'modify_price',
        width: 120,
        slotName: 'modify_price'
    },
    {
        title: '天-D',
        dataIndex: 'day',
        width: 70,
    },
    {
        title: '吨-T',
        dataIndex: 'weight',
        width: 80,
    },
    {
        title: '车-C',
        dataIndex: 'car_no_value',
        width: 80,
    },
    {
        title: '箱-X',
        dataIndex: 'box',
        width: 140,
    },
    {
        title: '计费规则',
        dataIndex: 'chi_price_role',
        width: 140,
    },
    {
        title: '备注',
        dataIndex: 'remark',
        width: 140,
        slotName: 'remark'
    },
    {
        title: '操作',
        dataIndex: 'caozuo',
        slotName: 'caozuo',
        width: 80,
    },
];
const handleSelect = (e, index, indexs) => {
    // if(itemList.value[index].detail[indexs].pay_real_price != ''){
    //     gethandleShuilv(index,indexs) 
    // }
    price_typeList.value.map((v, i) => {
        if (v.key == e) {
            itemList.value[index].detail[indexs].pay_name = v.title
        }
    })

}
const handleSelectcb = (e, index, indexs) => {
    // if(itemList.value[index].detail[indexs].pay_real_price != ''){
    //     gethandleShuilv(index,indexs) 
    // }
    price_typeList.value.map((v, i) => {
        if (v.key == e) {
            cbitemList.value[index].detail[indexs].pay_name = v.title
        }
    })

}
const handleYuanInput = (e, index, indexs) => {
    console.log(e)
    itemList.value[index].detail[indexs].pay_real_price = e
}
const handleYuanInputcb = (e, index, indexs) => {
    console.log(e)
    cbitemList.value[index].detail[indexs].pay_real_price = e
}
const handleInput = (e, index, indexs) => {
    // if(itemList.value[index].detail[indexs].price_type != ''){
    //     gethandleShuilv(index,indexs) 
    // }
}
const handleInputs = (e, index, indexs) => {
    console.log(cbitemList.value, index)
    if (cbitemList.value[index].detail[indexs].pay_real_price != '' && cbitemList.value[index].detail[indexs].no_tax_price != '') {
        cbitemList.value[index].detail[indexs].tax_price = (cbitemList.value[index].detail[indexs].pay_real_price - 0) - (cbitemList.value[index].detail[indexs].no_tax_price - 0)
    }
}
const handleDeptSelect = (e, index, indexs) => {
    paydept_list.value.map((v, i) => {
        if (v.id == e) {
            cbitemList.value[index].detail[indexs].dept_type = v.type
        }
    })

}
const handleTab = (index) => {
    console.log(index)
    tab.value = index
    if (index == 1) {
        getdaozhanList()
    } else {
        getdaozhanCBList()
    }
}
const handelavailableAmount = (dept_id) => {
    request({
        url: "financial/payOrder/deptList",
        method: "get",
        params: {
            page: 1,
            pageSize: 10,
            id: dept_id
        },
    }).then(resx => {
        availableAmount.value = resx.data.items[0].money
    })
}
onMounted(() => {
    console.log("props.item:", props.item)
    commonApi.getDict("price_type").then((res) => {
        res.data.map((v, i) => {
            v.keywords = [
                v.title,
                pinyin(v.title, { toneType: 'none', pattern: 'first' }).split(' ').join(''),
                pinyin(v.title, { toneType: 'none', pattern: 'first' }).split(' ').join('').toUpperCase()
            ]
        })
        price_typeList.value = res.data;
    });
    getdaozhanList(props.item.list)
    handleDeptList()
    handlepayDeptList()
    handelavailableAmount(itemList.value[0].pay_dept_id)
    handleShujuFormat()
})
const getdaozhanCBList = () => {
    request({
        url: 'financial/costOrder/index',
        method: 'get',
        params: cbitemData.value
    }).then(res => {
        let params = res.data.items
        let number = 0
        params.map((v, i) => {
            v.payment_id = ''
            v.jiesuan = ''
            v.pay_dept_id = ''
            v.is_confirm = 1
            v.pay_dept_id = v.dept_id
            let arr = []
            let arrs = []
            if (v.pay_status == 1) {
                number += (v.pay_price - 0)
            }
            v.detail.map((vv, ii) => {
                // vv.car_nos = vv.car_no;
                vv.dept_type = vv.type == 1 ? 3 : vv.type == 2 ? 4 : vv.type == 3 ? 5 : ""
                vv.type = 0
                vv.caozuo = ''
                vv.pay_dept_id = vv.pay_dept_id
                // if(v.prediction_id){
                vv.car_nos = v.prediction.car_no
                vv.no_tax_price = (vv.no_tax_price - 0).toFixed(2)
                vv.tax_price = (vv.tax_price - 0).toFixed(2)
                vv.pay_real_price = (vv.pay_real_price - 0).toFixed(2)
                vv.pay_price = (vv.pay_price - 0).toFixed(2)
                // }else{
                // if(v.prediction_order_id != 0 && v.prediction_driver_order_id == 0){  //  补费
                //     vv.car_nos = ''
                // }else{  // 装车收费
                //     if(vv.order_detail.prediction_id == 0){
                //     vv.car_nos = vv.order_detail.wareuserdetail.car_no
                //     }else{
                //     vv.car_nos = vv.order_detail.prediction.car_no
                //     }
                // }
                // }
                if (vv.pay_price != '0.00') {
                    arr.push(vv)
                }
            })
            v.detail = handleSOrt(arr)
            v.detail = handleWeizhi(v.detail)
            if (v.pay_status != 2) {
                v.disabled = true
            }
            if (v.pay_status == 2 && v.is_wait_check == 1) {
                v.disabled = true
            }
            v.order_no = v.driver_order?.order_no || ''
        })
        cbitemList.value = params
        handleShujuFormatCB()
    })
}
const gethandleShuilv = (index, indexs) => {
    request({
        url: "financial/payOrder/get_tax_price",
        method: "post",
        data: {
            price_type: itemList.value[index].detail[indexs].price_type,
            price: itemList.value[index].detail[indexs].pay_real_price,
        },
    }).then((res) => {
        console.log(res)
        itemList.value[index].detail[indexs].no_tax_price = res.data.no_tax_price
        itemList.value[index].detail[indexs].tax_price = res.data.tax_price
    });
}
const getaccount = () => {
    request({
        url: "system/dataDict/index",
        method: "get",
        params: {
            page: 1,
            pageSize: 10,
            type_id: 41
        },
    }).then((res) => {
        opening_bank.value = res.data.items[0].value
        account.value = res.data.items[1].value
        account_name.value = res.data.items[2].value
    });
}
const handleConsole = () => {
    console.log(itemList.value)
}
const handleCel = () => {  // 取消支付
    emit('quxiao')
}
const xiugaiids = ref([])
const handleZhifu = () => {
    let arr = []
    let err = 0    //  错误提示   1 没有选择付款人  2 实际金额为空或为负数  3 计费类型  4 收费项目  5 原金额  6 请选择账单
    // console.log('itemList',itemList.value)
    console.log(tab.value)
    if (tab.value == 1) {
        itemList.value.map((v, i) => {
            if (v.is_confirm == 1) {
                arr.push(JSON.parse(JSON.stringify(v)))
                if (v.pay_dept_id == '') {
                    err = 1
                }
                v.detail.map((vv, ii) => {
                    if ((vv.type == 0) && vv.is_confirm == 1) {
                        if (vv.pay_real_price == '' || (vv.pay_real_price - 0) < 0) {
                            err = 2
                        }
                    }
                    if (vv.type == 1) {
                        if (vv.price_type != '' || vv.pay_name != '' || vv.modify_price != '' ) {
                            if (vv.price_type == '') {
                                err = 3
                            }
                            if (vv.pay_name == '') {
                                err = 4
                            }
                            if (vv.modify_price == '' || (vv.modify_price - 0) < 0) {
                                err = 2
                            }
                        }

                    }
                })
            }
        })
        if (arr.length == 0) {
            err = 6
        }
        if (err == 1) {
            return Message.error('请选择付款人')
        } else if (err == 2) {
            return Message.error('修改金额不能为空')
        } else if (err == 3) {
            return Message.error('请选择计费类型')
        } else if (err == 4) {
            return Message.error('请输入收费项目')
        } else if (err == 5) {
            return Message.error('原金额不能为空或为负数')
        } else if (err == 6) {
            return Message.error('请选择账单')
        } else {
            arr.map((v, i) => {
                let detailArr = []
                v.detail.map((vv, ii) => {
                    // console.log('vv',vv)
                    if ((vv.type == 0) && vv.is_confirm == 1) {
                        detailArr.push(vv)
                    }
                    if (vv.type == 1) {
                        if (vv.price_type != '' && vv.pay_name != '' && vv.modify_price != '' ) {
                            detailArr.push(vv)
                        }

                    }
                })
                v.detail = detailArr
            })
            console.log(arr)
            let pay_type = itemList.value[0].detail[0].prediction.contract.pay_method.split(',')
            request({
                url: 'financial/payOrder/updateOrder',
                method: 'post',
                data: {
                    items: arr
                }
            }).then(res => {
                if(res.data.ids.length > 0){
                    zhifuShow.value = true
                    xiugaiids.value = res.data.ids
                    getaccount()
                    handleshoujuItem(arr)
                }else{
                    emit("shuaxin")
                    Message.success(res.message);
                }
                
                jiesuanOptions.value.map((v, i) => {
                    pay_type.map((vv, ii) => {
                        if (vv == v.value) {
                            jiesuan.value = v.value
                            v.disabled = false
                        }
                    })

                })
            })
        }
    } else {
        cbitemList.value.map((v, i) => {
            if (v.is_confirm == 1) {
                console.log(v)
                arr.push(JSON.parse(JSON.stringify(v)))

                v.detail.map((vv, ii) => {
                    if (vv.pay_dept_id == '') {
                        err = 1
                    }
                    if ((vv.type == 0) && vv.is_confirm == 1) {
                        if (vv.pay_real_price == '' || (vv.pay_real_price - 0) < 0) {
                            err = 2
                        }
                    }
                    if (vv.type == 1) {
                        if (vv.price_type != '' || vv.pay_name != '' || vv.pay_price != '' || vv.pay_real_price != '') {
                            if (vv.price_type == '') {
                                err = 3
                            }
                            if (vv.pay_name == '') {
                                err = 4
                            }
                            if (vv.pay_price == '' || (vv.pay_price - 0) < 0) {
                                err = 5
                            }
                            if (vv.pay_real_price == '' || (vv.pay_real_price - 0) < 0) {
                                err = 2
                            }
                        }

                    }
                })
            }
        })
        if (arr.length == 0) {
            err = 6
        }
        if (err == 1) {
            return Message.error('请选择收费公司')
        } else if (err == 2) {
            return Message.error('实际金额不能为空或为负数')
        } else if (err == 3) {
            return Message.error('请选择计费类型')
        } else if (err == 4) {
            return Message.error('请输入收费项目')
        } else if (err == 5) {
            return Message.error('请输入原金额')
        } else if (err == 6) {
            return Message.error('请选择账单')
        } else {
            arr.map((v, i) => {
                let detailArr = []
                v.detail.map((vv, ii) => {
                    if ((vv.type == 0) && vv.is_confirm == 1) {
                        detailArr.push(vv)
                    }
                    if (vv.type == 1) {
                        if (vv.price_type != '' && vv.pay_name != '' && vv.pay_price != '' && vv.pay_real_price != '') {
                            detailArr.push(vv)
                        }

                    }
                })
                v.detail = detailArr
            })
            request({
                url: 'financial/costOrder/confirm',
                method: 'post',
                data: {
                    items: arr
                }
            }).then(res => {
                emit("shuaxin")
                Message.success(res.message);
            })

        }
    }



}
const handleshoujuItem = (arr)=>{
        let obj = JSON.parse(JSON.stringify(arr[0]))
            obj.detail = []
            arr.map((item)=>{
                obj.detail.push(...item.detail)
            })
            console.log("obj.detail:",obj.detail)
            let falgTrue = []
            obj.detail.map((item)=>{
                if(falgTrue.length == 0){
                    falgTrue.push(item) 
                }else{
                    let num = falgTrue.findIndex((ite)=>{
                    return ite.pay_name == item.pay_name
                })
                if(num == -1){
                    falgTrue.push(item) 
                }else{
                    falgTrue[num].pay_real_price = (falgTrue[num].modify_price - 0) + (item.modify_price - 0)
                }
                }
                
            })
            falgTrue.map((item)=>{
                item.pay_real_price = (item.modify_price - 0).toFixed(2)
            })
            obj.detail = falgTrue
            shoujuItem.value = obj
            
    }
const handelzhifuOk = async () => { // 支付成功
    let obj = {}
    let ids = []
    itemList.value.map((v, i) => {
        if (v.is_confirm == 1) {
            ids.push(v.id)
        }
    })
    if (jiesuan.value == '1' || jiesuan.value == '2') {
        obj.pay_type = jiesuan.value == 1 ? 'money' : 'periodic'
        obj.ids = xiugaiids.value
        obj.pay_date = pay_date.value
    }
    if (jiesuan.value == '3') {
        obj.pay_type = 'now_pay'
        obj.ids = xiugaiids.value
        obj.now_pay_type = zhifu.value
        obj.transfer_proof_images = fileList.value
        obj.payment_method = zhifu.value
        obj.settlement_method = 1
        obj.notes = ''
        obj.pay_date = pay_date.value
        // obj.pay_order_id = this.zhifu_id    // 交易单号
        obj.dept_id = itemList.value[0].dept_id    // 公司
        obj.opening_bank = opening_bank.value    // 开户行
        obj.account = account.value    // 收款账户
        obj.account_name = account_name.value    // 开户行名称
    }

    let res = await request({
        url: "financial/payOrder/pay",
        method: "post",
        data: obj,
    })
    if (res.code == 200) {
        // emit("shuaxin")
        shoujuShow.value = true
        zhifuShow.value = false
        Message.success(res.message)
        return true
    } else {
        Message.success(res.message);
        return false
    }

    // // .then((res) => {
    //     emit("shuaxin")
    //     Message.success(res.message);
    // });
}

const spanMethodAll = ({ record, rowIndex, columnIndex }) => {
    if (rowIndex === record.weizhi - record.weizhizong && columnIndex === 0) {
        return { rowspan: record.weizhizong, colspan: 1 }
    }
};
const filterOption = (v, option) => {
    return option.keywords.some(keywords => keywords.includes(v))
}
const handleDeptList = () => {   //  获取公司列表
    request({
        url: 'system/dept/remote',
        method: 'post',
        data: {
            openPage: false,
            remoteOption: {
                filter: {
                    type: ['=', 2],
                    status: ['=', 1]
                },
                select: ["id", "name"],
                sort: { id: "desc" }
            }
        }
    }).then(res => {
        res.data.map((v, i) => {
            v.keywords = [
                v.name,
                pinyin(v.name, { toneType: 'none', pattern: 'first' }).split(' ').join(''),
                pinyin(v.name, { toneType: 'none', pattern: 'first' }).split(' ').join('').toUpperCase()
            ]
        })
        dept_list.value = res.data
    })
}
const handlepayDeptList = () => {   //  获取公司列表
    request({
        url: 'system/dept/remote',
        method: 'post',
        data: {
            openPage: false,
            remoteOption: {
                filter: {
                    type: ['>', 2],
                    status: ['=', 1]
                },
                select: ["id", "name", "type"],
                sort: { id: "desc" }
            }
        }
    }).then(res => {
        res.data.map((v, i) => {
            v.keywords = [
                v.name,
                pinyin(v.name, { toneType: 'none', pattern: 'first' }).split(' ').join(''),
                pinyin(v.name, { toneType: 'none', pattern: 'first' }).split(' ').join('').toUpperCase()
            ]
        })
        paydept_list.value = res.data
    })
}
const getdaozhanList = (lists) => {
    let number = 0
    let arres = JSON.parse(JSON.stringify(lists))
    arres.map((v, i) => {
        v.payment_id = ''
        v.jiesuan = ''
        v.pay_dept_id = ''
        v.is_confirm = 1
        let detailArr = []
        if (v.dept_id == 0) {
            v.pay_dept_id = v.prediction.dept_id
        } else {
            v.pay_dept_id = v.dept_id
        }
        let arr = []
        let arrs = []
        if (v.pay_status == 1) {
            number += (v.pay_price - 0)
        }
        v.detail.map((vv, ii) => {
            if(vv.is_confirm == 1){
                detailArr.push(vv) 
            } 
        })
        v.detail = detailArr
        v.detail.map((vv, ii) => {
            vv.type = 0
            vv.caozuo = ''
            vv.pay_dept_id = vv.dept_id
            vv.car_nos = vv.prediction.car_no
            vv.no_tax_price = (vv.no_tax_price - 0).toFixed(2)
            vv.tax_price = (vv.tax_price - 0).toFixed(2)
            vv.pay_real_price = (vv.pay_real_price - 0).toFixed(2)
            vv.pay_price = (vv.pay_price - 0).toFixed(2)
            vv.modify_price = (JSON.parse(JSON.stringify(vv.pay_real_price)) - 0).toFixed(2)
            if (vv.pay_price != '0.00') {
                arr.push(vv)
            }
        })
        v.detail = handleSOrt(arr)
        v.detail = handleWeizhi(v.detail)
        if (v.pay_status != 2) {
            v.disabled = true
        }
        if (v.pay_status == 2 && v.is_wait_check == 1) {
            v.disabled = true
        }
        v.order_no = v.driver_order?.order_no || ''
    })
    itemList.value = arres
    console.log(itemList.value)
    handelavailableAmount(itemList.value[0].pay_dept_id)
    handleShujuFormat()
}
const handleSelectPay_dept_id = (e, index) => {
    console.log('e:', e)
    console.log('index:', index)
    itemList.value[index].pay_dept_id = e
    handelavailableAmount(e)
}
const handleSOrt = (ceshiArr) => {
    let arr = []           // 最终数据
    let linshiArr = []     //  未匹配的放数组里
    let linshititle = ''   // 临时变量
    ceshiArr.map((v, i) => {
        if (i == 0) {
            linshititle = v.name
            arr.push(v)
        } else {
            if (linshititle == v.name) {
                arr.push(v)
            } else {
                linshiArr.push(v)
            }
        }
    })
    ceshiArr.map((v, i) => {
        if (linshiArr.length != 0) {
            linshiArr.map((vv, ii) => {
                if (ii == 0) {
                    linshititle = linshiArr[0].name
                    arr.push(linshiArr.shift())
                } else {
                    if (linshititle == vv.name) {
                        arr.push(linshiArr.slice(ii, 1))
                    }
                }

            })

        }
    })
    arr.sort((a, b) => a.car_nos.localeCompare(b.car_nos));
    return arr
}
const handleWeizhi = (detail) => {
    console.log('detail:', detail)
    let carArr = []
    let carArrs = []
    detail.map((vv, ii) => {
        carArr.push(vv.car_nos)
        carArrs.push({ car_no: vv.car_nos, prediction_id: vv.prediction_id, billing_node: vv.billing_node })
    })
    var newArr = carArr.filter(function (item, index) {  // 获取有多少车号
        return carArr.indexOf(item) === index;  // 因为indexOf 只能查找到第一个  
    });
    console.log('newArr', newArr)
    let numArr = []
    newArr.map((vv, ii) => {
        let num = 0
        let name = ''
        let prediction_id = ''
        let billing_node = ''
        carArrs.map((vvv, iii) => {
            if (vv == vvv.car_no) {
                num++
                name = vvv.car_no
                billing_node = vvv.billing_node
                prediction_id = vvv.prediction_id
            }
        })
        numArr.push({ car_no: name, weizhi: num, weizhizong: num, prediction_id, billing_node })
    })
    console.log('numArr', numArr)
    let weizhiArr = []
    let weizhinum = 0
    numArr.map((vv, ii) => {
        weizhinum += vv.weizhi
        weizhiArr.push({ car_no: vv.car_no, weizhi: weizhinum, weizhizong: vv.weizhizong, billing_node: vv.billing_node, prediction_id: vv.prediction_id })
    })
    let tianjia = []
    console.log('weizhiArr', weizhiArr)
    weizhiArr.map((vv, ii) => {
        tianjia = [{ prediction_id: vv.prediction_id, billing_node: vv.billing_node, car_nos: vv.car_no, price_type: '', no_tax_price: '', tax_price: '',modify_price:'', pay_name: '', pay_price: '', pay_real_price: '', day: '', weight: '', car_no_value: '', box: '', price_role: '', remark: '', type: 1, caozuo: '', is_confirm: 1 }, { car_nos: vv.car_no, price_type: '', pay_name: '', no_tax_price: '', tax_price: '', pay_price: '', day: '', weight: '', car_no_value: '', box: '', price_role: '', remark: '', type: 2, caozuo: '' }]
        detail.splice((vv.weizhi + (2 * ii)), 0, ...tianjia)
    })
    carArr = []
    detail.map((vv, ii) => {
        carArr.push(vv.car_nos)
    })
    var newArr = carArr.filter(function (item, index) {  // 获取有多少车号
        return carArr.indexOf(item) === index;  // 因为indexOf 只能查找到第一个  
    });
    numArr = []
    newArr.map((vv, ii) => {
        let num = 0
        let name = ''
        carArr.map((vvv, iii) => {
            if (vv == vvv) {
                num++
                name = vvv
            }
        })
        numArr.push({ car_no: name, weizhi: num, weizhizong: num })
    })
    weizhiArr = []
    weizhinum = 0
    numArr.map((vv, ii) => {
        weizhinum += vv.weizhi
        weizhiArr.push({ car_no: vv.car_no, weizhi: weizhinum, weizhizong: vv.weizhizong })
    })
    detail.map((vv, ii) => {
        weizhiArr.map((vvv, iii) => {
            if (vv.car_nos == vvv.car_no) {
                vv.weizhi = vvv.weizhi
                vv.weizhizong = vvv.weizhizong
            }
        })
    })
    return detail
}
const handleAdd = (index, rowIndex, type) => {
    console.log(rowIndex)
    if (tab.value == 1) {
        itemList.value.map((v, i) => {
            if (i == index) {
                let carArr = []
                if (type == 1) {  // 新增
                    console.log('detail:', v.detail)
                    let car_nos = v.detail[rowIndex - 1].car_nos
                    let prediction_id = v.detail[rowIndex - 1].prediction_id
                    let billing_node = v.detail[rowIndex - 1].billing_node
                    v.detail.splice(rowIndex, 0, { prediction_id, billing_node, car_nos: car_nos, price_type: '', pay_name: '', pay_price: '', pay_real_price: '', day: '', no_tax_price: '', tax_price: '',modify_price:'', weight: '', car_no_value: '', box: '', price_role: '', remark: '', type: 1, caozuo: '', is_confirm: 1, })
                } else {  // 删除
                    v.detail.splice(rowIndex, 1)
                }
                console.log(v.detail)
                v.detail.map((vv, ii) => {
                    carArr.push(vv.car_nos)
                })
                var newArr = carArr.filter(function (item, index) {  // 获取有多少车号
                    return carArr.indexOf(item) === index;  // 因为indexOf 只能查找到第一个  
                });
                let numArr = []
                newArr.map((vv, ii) => {
                    let num = 0
                    let name = ''
                    carArr.map((vvv, iii) => {
                        if (vv == vvv) {
                            num++
                            name = vvv
                        }
                    })
                    numArr.push({ car_no: name, weizhi: num, weizhizong: num })
                })
                let weizhiArr = []
                let weizhinum = 0
                numArr.map((vv, ii) => {
                    weizhinum += vv.weizhi
                    weizhiArr.push({ car_no: vv.car_no, weizhi: weizhinum, weizhizong: vv.weizhizong })
                })
                v.detail.map((vv, ii) => {
                    weizhiArr.map((vvv, iii) => {
                        if (vv.car_nos == vvv.car_no) {
                            vv.weizhi = vvv.weizhi
                            vv.weizhizong = vvv.weizhizong
                        }
                    })
                })
            }
        })
    } else {
        cbitemList.value.map((v, i) => {
            if (i == index) {
                let carArr = []
                if (type == 1) {  // 新增
                    console.log('detail:', v.detail)
                    let car_nos = v.detail[rowIndex - 1].car_nos
                    let prediction_id = v.detail[rowIndex - 1].prediction_id
                    let billing_node = v.detail[rowIndex - 1].billing_node
                    v.detail.splice(rowIndex, 0, { prediction_id, billing_node, pay_dept_id: '', car_nos: car_nos, price_type: '', pay_name: '', pay_price: '', pay_real_price: '', day: '', no_tax_price: '', tax_price: '', weight: '', car_no_value: '', box: '', price_role: '', remark: '', type: 1, caozuo: '', is_confirm: 1, })
                } else {  // 删除
                    v.detail.splice(rowIndex, 1)
                }
                console.log(v.detail)
                v.detail.map((vv, ii) => {
                    carArr.push(vv.car_nos)
                })
                var newArr = carArr.filter(function (item, index) {  // 获取有多少车号
                    return carArr.indexOf(item) === index;  // 因为indexOf 只能查找到第一个  
                });
                let numArr = []
                newArr.map((vv, ii) => {
                    let num = 0
                    let name = ''
                    carArr.map((vvv, iii) => {
                        if (vv == vvv) {
                            num++
                            name = vvv
                        }
                    })
                    numArr.push({ car_no: name, weizhi: num, weizhizong: num })
                })
                let weizhiArr = []
                let weizhinum = 0
                numArr.map((vv, ii) => {
                    weizhinum += vv.weizhi
                    weizhiArr.push({ car_no: vv.car_no, weizhi: weizhinum, weizhizong: vv.weizhizong })
                })
                v.detail.map((vv, ii) => {
                    weizhiArr.map((vvv, iii) => {
                        if (vv.car_nos == vvv.car_no) {
                            vv.weizhi = vvv.weizhi
                            vv.weizhizong = vvv.weizhizong
                        }
                    })
                })
            }
        })
    }

    console.log(itemList.value)
}
const handletuhuanPriceType = (id) => {
    let name = ''
    price_typeList.value.map((v, i) => {
        if (v.key == id) {
            name = v.title
        }
    })
    return name
}
const handleZongPrice = (status) => {
    let num = 0
    let zongpay_real_price = 0
    let zongmodify_price = 0
    console.log('itemList:',itemList.value)
    itemList.value.map((v, i) => {
        v.detail.map((vv, ii) => {
            if (vv.is_confirm == 1 && status == 1) {
                if (vv.pay_price == '') {
                    num += 0
                } else {
                    num += (vv.pay_price - 0)
                }

            }
            if (vv.is_confirm == 1 && status == 2 ) {
                if (vv.pay_real_price == '') {
                    zongpay_real_price += 0
                } else {
                    zongpay_real_price += (vv.pay_real_price - 0)
                }
                if (vv.modify_price == '') {
                    zongmodify_price += 0
                } else {
                    zongmodify_price += (vv.modify_price - 0)
                }
                num = (zongmodify_price - zongpay_real_price)
            }
            if (vv.is_confirm == 1 && status == 3) {
                if (vv.no_tax_price == '') {
                    num += 0
                } else {
                    num += (vv.no_tax_price - 0)
                }
            }
            if (vv.is_confirm == 1 && status == 4) {
                if (vv.tax_price == '') {
                    num += 0
                } else {
                    num += (vv.tax_price - 0)
                }
            }
        })
    })
    return num.toFixed(2)
}
const handleZongPricecb = (status) => {
    let num = 0
    cbitemList.value.map((v, i) => {
        v.detail.map((vv, ii) => {
            if (vv.is_confirm == 1 && status == 1) {
                if (vv.pay_price == '') {
                    num += 0
                } else {
                    num += (vv.pay_price - 0)
                }

            }
            if (vv.is_confirm == 1 && status == 2) {
                if (vv.pay_real_price == '') {
                    num += 0
                } else {
                    num += (vv.pay_real_price - 0)
                }
            }
            if (vv.is_confirm == 1 && status == 3) {
                if (vv.no_tax_price == '') {
                    num += 0
                } else {
                    num += (vv.no_tax_price - 0)
                }
            }
            if (vv.is_confirm == 1 && status == 4) {
                if (vv.tax_price == '') {
                    num += 0
                } else {
                    num += (vv.tax_price - 0)
                }
            }
        })
    })
    return num.toFixed(2)
}

</script>

<style lang="less" scoped>
.zuidaBox {
    max-height: 700px;
    overflow: auto;
    scrollbar-width: none;
}

.zuidaBox::-webkit-scrollbar {
    display: none;
    /* 对于 Chrome, Safari 和 Opera */
}

.box {

    margin-bottom: 20px;

    &:last-child {
        margin-bottom: 0;
    }
}

.tab_border{
    border-top: 1px solid rgba(0, 0, 0, .15);
    border-left: 1px solid rgba(0, 0, 0, .15);
}
.bor_r{
    border-right: 1px solid rgba(0, 0, 0,.15);
}
.bor_b{
    border-bottom: 1px solid rgba(0, 0, 0,.15);
}
.pad412{
    padding: 4px 12px;
}

.chek {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, .15);
}

.act_chek {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid rgb(22, 93, 255);
    background: rgb(22, 93, 255);
}
</style>